1
|
|
|
import deepEqual from 'deep-equal'; |
2
|
|
|
import { getLastUpdate } from './lastUpdate'; |
3
|
|
|
|
4
|
|
|
export function shouldGridUpdate(nextProps) { |
5
|
|
|
let result = true; |
|
|
|
|
6
|
|
|
|
7
|
|
|
const { reducerKeys, stateKey, store } = this.props; |
8
|
|
|
|
9
|
|
|
const nextUpdate = getLastUpdate(store, stateKey, reducerKeys); |
10
|
|
|
|
11
|
|
|
result = ( |
12
|
|
|
!deepEqual(nextUpdate, this._lastUpdate) |
13
|
|
|
|| !equalProps(nextProps, this._lastProps) |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
this._lastUpdate = nextUpdate; |
17
|
|
|
this._lastProps = nextProps; |
18
|
|
|
|
19
|
|
|
return result; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
export function shouldPagerUpdate(nextProps, nextState) { |
23
|
|
|
|
24
|
|
|
let result = true; |
|
|
|
|
25
|
|
|
|
26
|
|
|
const limitedNextProps = { |
27
|
|
|
gridData: nextProps.gridData, |
28
|
|
|
state: this.state |
29
|
|
|
}; |
30
|
|
|
|
31
|
|
|
const limitedProps = { |
32
|
|
|
gridData: this.props.gridData, |
33
|
|
|
state: nextState |
34
|
|
|
}; |
35
|
|
|
|
36
|
|
|
result = ( |
37
|
|
|
!deepEqual(limitedNextProps, limitedProps) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
return result; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
export function shouldHeaderUpdate() { |
44
|
|
|
// let result = true; |
45
|
|
|
// to do, stop this |
46
|
|
|
return true; |
47
|
|
|
|
48
|
|
|
/* eslint-disable no-unreachable */ |
49
|
|
|
|
50
|
|
|
// const menuState = state => |
51
|
|
|
// state && state.get('header-row'); |
52
|
|
|
|
53
|
|
|
// const limitedNextProps = { |
54
|
|
|
// columns: nextProps.columns, |
55
|
|
|
// menuState: menuState(nextProps.menuState), |
56
|
|
|
// state: nextState |
57
|
|
|
// }; |
58
|
|
|
|
59
|
|
|
// const limitedProps = { |
60
|
|
|
// columns: this.previousColumns, |
61
|
|
|
// menuState: menuState(this.props.menuState), |
62
|
|
|
// state: this.state |
63
|
|
|
// }; |
64
|
|
|
|
65
|
|
|
// result = ( |
66
|
|
|
// !deepEqual(limitedNextProps, limitedProps) |
67
|
|
|
// ); |
68
|
|
|
|
69
|
|
|
// this.previousColumns = this.props.columns.slice(); |
70
|
|
|
|
71
|
|
|
// return result; |
72
|
|
|
|
73
|
|
|
/* eslint-enable no-unreachable */ |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
export function shouldRowUpdate(nextProps) { |
77
|
|
|
let result = true; |
|
|
|
|
78
|
|
|
|
79
|
|
|
// unique key created by setData action/reducer |
80
|
|
|
const key = nextProps.row.get('_key'); |
81
|
|
|
|
82
|
|
|
const limitedNextProps = { |
83
|
|
|
columns: slimColumn(nextProps.columns), |
84
|
|
|
isEdited: isEdited(nextProps.editorState, key), |
85
|
|
|
currentValues: isEdited(nextProps.editorState, key) |
86
|
|
|
? nextProps.editorState.get(key) |
87
|
|
|
: null, |
88
|
|
|
isMenuShown: isMenuShown(nextProps.menuState, key), |
89
|
|
|
row: nextProps.row, |
90
|
|
|
index: nextProps.index, |
91
|
|
|
isSelected: isSelected(nextProps.selectedRows, key), |
92
|
|
|
isDragging: nextProps.isDragging |
93
|
|
|
}; |
94
|
|
|
|
95
|
|
|
const limitedProps = { |
96
|
|
|
columns: this.previousColumns, |
97
|
|
|
isEdited: isEdited(this.props.editorState, key), |
98
|
|
|
currentValues: isEdited(this.props.editorState, key) |
99
|
|
|
? this.props.editorState.get(key) |
100
|
|
|
: null, |
101
|
|
|
isMenuShown: isMenuShown(this.props.menuState, key), |
102
|
|
|
row: this.props.row, |
103
|
|
|
index: this.props.index, |
104
|
|
|
isSelected: isSelected(this.props.selectedRows, key), |
105
|
|
|
isDragging: this.props.isDragging |
106
|
|
|
}; |
107
|
|
|
|
108
|
|
|
this.previousColumns = slimColumn(this.props.columns.slice()); |
109
|
|
|
|
110
|
|
|
result = ( |
111
|
|
|
!deepEqual(limitedNextProps, limitedProps) |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
return result; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
export const isSelected = (rows, key) => Boolean(rows && rows.get(key)); |
118
|
|
|
|
119
|
|
|
export const isMenuShown = (rows, key) => Boolean(rows && rows.get(key)); |
120
|
|
|
|
121
|
|
|
export const isEdited = (editorState, key) => Boolean( |
122
|
|
|
editorState |
123
|
|
|
&& editorState.get(key) |
124
|
|
|
&& editorState.get(key).values |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
export const slimColumn = cols => |
128
|
|
|
cols.map(col => ({ hidden: col.hidden, dataIndex: col.dataIndex })); |
129
|
|
|
|
130
|
|
|
export const equalProps = (props = {}, newProps = {}) => { |
131
|
|
|
return props.height === newProps.height |
132
|
|
|
&& deepEqual(props.classNames, newProps.classNames) |
133
|
|
|
&& deepEqual(props.events, newProps.events); |
134
|
|
|
}; |
135
|
|
|
|